<template>
    <div class="">
        <div class="outmain ba_f heighthv pad_20 bor_rad5">
            <div class="shuju_title mar_b20">
                <div class="shuju_title_text">
                    <span>语音合成设置</span>
                </div>
            </div>
            <div class="ba_f8 pad_20">
                <div class="lh25 msgtext fon_12">
                    温馨提示：请到百度AI开发平台上创建语音合成应用；<br>
                    申请地址；<a href="https://ai.baidu.com/?track=cp:aipinzhuan|pf:pc|pp:AIpingtai|pu:title|ci:|kw:10005792" target="_blank" class="color_9">https://ai.baidu.com/?track=cp:aipinzhuan|pf:pc|pp:AIpingtai|pu:title|ci:|kw:10005792</a><br>
                </div>
            </div>
            <div class="mar_t20 flex-bet flex-y-top">
                <div class="flex-g-1">
                    <el-form ref="form" :model="form" label-width="180px">
                        <el-form-item label="APP ID" :required='true' prop="appId">
                            <el-input v-model="form.appId" placeholder="请输入appId"></el-input>
                        </el-form-item>
                        <el-form-item label="API KEY" :required='true' prop="apiKey">
                            <el-input v-model="form.apiKey" placeholder="请输入apiKey"></el-input>
                        </el-form-item>
                        <el-form-item label="SECRET KEY" :required='true' prop="secretKey">
                            <el-input v-model="form.secretKey" placeholder="请输入secretKey"></el-input>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
        </div>
        <div class="mar_t20 ba_f pad_20 t_c">
            <el-button type="primary" @click="submitForm">保存</el-button>
        </div>
    </div>
</template>
<script>
    import {getConfig,postConfig} from "@/api/setup";


    export default {
        created() {
            this.bus.$emit('loading', true);
            this.init();
        },
        components: {},
        data() {
            return {
                form: {
                    appId: '',
                    apiKey: '',
                    secretKey: '',
                },
                id:'',
            }
        },
        methods: {
            async init(){
                const {data} = await getConfig({ident: 'voiceSet'});
                this.form2 = this.form
                this.form = Object.assign(this.form2, data);
                this.bus.$emit('loading', false)
            },
            async submitForm() {
                this.$refs["form"].validate(async (valid) => {
                    if (valid) {
                        this.form.ident = 'voiceSet'
                        this.form.identName = '语音合成'
                        const {msg} = await postConfig(this.form);
                        this.$baseMessage(msg, "success");
                        this.$router.go(-1)
                    } else {
                        return false;
                    }
                });
            },
        }
    }
</script>
